package net.wangds.web.entrypoint;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * 返回集合类型结果.
 * @param <T> 集合类成员类型.
 */
@ApiModel(value="返回记录及的应答", description = "返回体为对象列表的应答.", parent = BaseResp.class)
public class BaseMultipleResp<T> extends BaseResp<List<T>> {

    /**
     * 总数.
     */
    @ApiModelProperty(value = "记录总数", required = true)
    private long total;

    /**
     * 页码，从1开始.
     */
    @ApiModelProperty(value = "列表的页码， 首页为页码为\"1\".", required = true)
    private int pageIndexB1;

    /**
     * 页面大小.
     */
    @ApiModelProperty(value = "页面大小，即每页最多记录数.", required = true)
    private int pageSize;

    /**
     * 查询关键字列表.
     */
    @ApiModelProperty(value = "查询时指定的查询关键字或条件", required = true)
    private String keywords;

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPageIndexB1() {
        return pageIndexB1;
    }

    public void setPageIndexB1(int pageIndexB1) {
        this.pageIndexB1 = pageIndexB1;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public static <T> BaseMultipleResp<T> list(List<T> list){
        return (BaseMultipleResp<T>)new BaseMultipleResp<T>().body(list);
    }

    public BaseMultipleResp<T> keywords(String keywords){
        this.keywords = keywords;
        return this;
    }

    public BaseMultipleResp<T> total(long total){
        this.total = total;
        return this;
    }

    public BaseMultipleResp<T> pageIndexB1(int index){
        this.pageIndexB1 = index;
        return this;
    }

    public BaseMultipleResp<T> pageSize(int pageSize){
        this.pageSize = pageSize;
        return this;
    }

    public BaseMultipleResp<T> fill(List<T> list){
        int size = list.size();
        this.body(list);
        this.pageIndexB1(1);
        this.pageSize(size);
        this.total(size);
        this.code(0);
        this.msg("ok");
        return this;
    }

}
